<template>
  <div class="app-container">
    <ContentWrap>
      <el-row :gutter="20">
        <el-col :span="4">
          <RegionTree node-type="1" :node-click="handleNodeClick"/>
        </el-col>
        <el-col :span="20" class="content-container">
          <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
                   label-width="68px">
            <el-form-item label="用户编号" prop="terminalID">
              <el-input
                v-model="queryParams.terminalID"
                placeholder="请输入用户编号"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="用户名称" prop="userName">
              <el-input
                v-model="queryParams.userName"
                placeholder="请输入用户编号"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="抄表时间" prop="freezeTime">
              <el-date-picker
                v-model="queryParams.freezeTime"
                type="month"
                value-format="yyyy-MM"
                placeholder="请选择抄表时间" @change="handleFreezeTimeChange">
              </el-date-picker>
            </el-form-item>
            <el-form-item>
              <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport">导出</el-button>
              <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
              <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
          </el-form>

          <el-table v-loading="loading" :data="terminalFreezeXbList" border :height="getAvailableHeight">
            <el-table-column type="index" width="40" align="center" label="#" :fixed="true"/>
            <!--          <el-table-column type="selection" width="55" align="center"/>-->
            <!--          <el-table-column label="设备归属租户" align="center" prop="tenantId"/>-->
            <!--          <el-table-column label="层级ID" align="center" prop="AreaID"/>-->
            <el-table-column label="用户编号" align="center" prop="terminalID"/>
            <el-table-column label="用户名称" align="center" prop="terminalsXb.userName"/>
            <el-table-column label="用水量(m³)" align="center" prop="cumulativeFlow"/>
            <el-table-column label="环比上月(%)" align="center" prop="hb"/>
            <el-table-column label="平均每日用水量(m³)" align="center" prop="userAvg"/>
            <el-table-column label="前3月平均用水量(m³)" align="center" prop="cumulativeFlowAvg"/>
            <el-table-column label="抄表时间" align="center" prop="freezeTime"/>
          </el-table>

          <pagination
            :total="total"
            :page-sizes="[15, 30, 45, 60]"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getList"
          />
        </el-col>
      </el-row>
    </ContentWrap>
  </div>
</template>

<script>
import {
  listTerminalFreezeXb,
  getTerminalFreezeXb,
  delTerminalFreezeXb,
  addTerminalFreezeXb,
  updateTerminalFreezeXb
} from "@/api/leakage/terminalFreezeXb";
import RegionTree from "@/views/leakage/components/RegionTree.vue";

export default {
  name: "TerminalFreezeXb",
  components: {RegionTree},
  data() {
    return {
      screenHeight: null,
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 小用户冻结数据表格数据
      terminalFreezeXbList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 15,
        terminalID: null,
        userName: null,
        freezeTime: null,
        AreaID: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    };
  },
  created() {
    this.getList();
    this.screenHeight = document.body.clientHeight
  },
  computed: {
    getAvailableHeight() {
      return this.screenHeight - 235
    },
  },
  methods: {
    /** 查询小用户冻结数据列表 */
    getList() {
      this.loading = true;
      listTerminalFreezeXb(this.queryParams).then(response => {
        this.terminalFreezeXbList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('swla2/terminalFreezeXb/export', {
        ...this.queryParams
      }, `户表数据.xlsx`)
    },
    handleNodeClick(node) {
      // this.editingZone = node
      this.queryParams.AreaID = node.areaId
      this.handleQuery()
    },
    handleFreezeTimeChange(val) {
    }
  }
};
</script>
